package com.ihd.ihardware.view.tzc.health.view;

import android.os.Bundle;
import android.view.View;

import com.ihd.ihardware.R;
import com.ihd.ihardware.common.AppConstans;
import com.ihd.ihardware.databinding.ActivityCountHisBinding;
import com.ihd.ihardware.pojo.EmptyRes;
import com.ihd.ihardware.pojo.ReportsRes;
import com.ihd.ihardware.view.tzc.health.viewmodel.CountHisViewModel;

import cn.wowjoy.commonlibrary.base.BaseActivity;
import cn.wowjoy.commonlibrary.base.BaseConsumer;
import cn.wowjoy.commonlibrary.utils.DialogUtils;
import cn.wowjoy.commonlibrary.utils.ToastUtils;

public class CountHisActivity extends BaseActivity<ActivityCountHisBinding, CountHisViewModel> {
    private String familyId;
    private String type;

    @Override
    protected void init(Bundle savedInstanceState) {
        mImmersionBar.statusBarDarkFont(false).init();

        familyId = (String) getIntent().getSerializableExtra("familyId");
        type = (String) getIntent().getSerializableExtra("type");

        binding.back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        setRx(AppConstans.REPORTS, new BaseConsumer<ReportsRes>() {
            @Override
            protected void onStart() {
                DialogUtils.waitingDialog(CountHisActivity.this);
            }

            @Override
            protected void onSuccess(ReportsRes mLiveData) {
                DialogUtils.dismiss(CountHisActivity.this);
                viewModel.setReport(mLiveData.getData());
            }

            @Override
            protected void onError(Throwable error) {
                DialogUtils.dismiss(CountHisActivity.this);
                ToastUtils.showShort(CountHisActivity.this, error.getMessage());
            }
        });

        setRx(AppConstans.DELWEIGHT, new BaseConsumer<EmptyRes>() {
            @Override
            protected void onStart() {
                DialogUtils.waitingDialog(CountHisActivity.this);
            }

            @Override
            protected void onSuccess(EmptyRes mLiveData) {
                DialogUtils.dismiss(CountHisActivity.this);
//                viewModel.mConcernedAdapter.notifyDataSetChanged();
                viewModel.reports(familyId, type);
            }

            @Override
            protected void onError(Throwable error) {
                DialogUtils.dismiss(CountHisActivity.this);
                ToastUtils.showShort(CountHisActivity.this, error.getMessage());
            }
        });

        binding.proRV.setAdapter(viewModel.mConcernedAdapter);
        viewModel.reports(familyId, type);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_count_his;
    }

    @Override
    protected Class getViewModelClass() {
        return CountHisViewModel.class;
    }
}
